package com.flyduck.system.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flyduck.system.entity.SysMenuEntity;
import com.flyduck.system.enums.StatusEnum;
import com.flyduck.system.mapper.SysMenuMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: flyduck-platform2
 * @description:
 * @author: flyduck
 * @create: 2021-04-23 14:54
 **/
@Repository
public class SysMenuDao extends ServiceImpl<SysMenuMapper, SysMenuEntity> {

    /**
     * 获取所有的菜单(未禁用且未删除)
     * @return
     */
    public List<SysMenuEntity> getAllMenus() {
        return this.baseMapper.selectList(
                new QueryWrapper<SysMenuEntity>()
                        .eq("status", StatusEnum.ENABLE.getValue())
        );
    }
    /**
     * 根据菜单id集合获取菜单集合
     * @param menuIds
     * @return
     */
    public List<SysMenuEntity> selectMenusByIds(List<Long> menuIds) {
        return this.baseMapper.selectList(
                new QueryWrapper<SysMenuEntity>().in("id", menuIds)
        );
    }

    /**
     * 根据父菜单id查询菜单集合
     * @param parentId
     * @return
     */
    public List<SysMenuEntity> findByParentId(Long parentId) {
        QueryWrapper<SysMenuEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id", parentId);
        return this.baseMapper.selectList(wrapper);
    }
}
